﻿@using ZBJF.Warranty.BLL
@using ZBJF.Warranty.Common.Enums
@using ZBJF.Warranty.Common.Enums.System
@using ZBJF.Warranty.Model
@using ZBJF.Warranty.WebProvider
@model ZBJF.Warranty.Model.SystemUser
@{
    var id = Model != null ? Model.ID : 0;
    var companyName = "";
    if (Model != null && Model.InsuranceCompanyID.HasValue)
    {
        companyName = Model.InsuranceCompany.CompanyName;
    }
}
@using (Html.BeginForm("Save", "Admin", FormMethod.Post, new { @class = "form-horizontal" }))
{
    @Html.HiddenFor(m => m.ID)
    <div class="control-group">
        <label class="control-label">用户账号:</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.UserAccount, new { @class = "col-sm-8", validate = "{required:true,messages:{required:'请输入账号名'}}" })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">所属系统:</label>
        <div class="controls">
            @Html.DropDownListFor(m => m.BelongApplicationType, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(ApplicationType)), new { validate = "{required:true,messages:{required:'请选择所属系统'}}" })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">账号类型:</label>
        <div class="controls">
            @Html.DropDownListFor(m => m.UserType, ConvertToSelector.Instance.EnumTypeConvertToSelectList(typeof(UserType)), new { validate = "{required:true,messages:{required:'请选择账号类型'}}",onchange="userTypeChange()" })
        </div>
    </div>
    <div class="control-group hidden" id="divInsuranceCompanyID">
        <label class="control-label">所属承保公司:</label>
        <div class="controls">
            @Html.TextBox("InsuranceCompanyName", companyName, new { @readonly = "readonly", @class = "select-icon", onclick = "showLayerOpen('选择承保公司','/PubModelDialog/InsuranceCompanySelector?chkStyle=radio&textid=InsuranceCompanyName&hiddenId=InsuranceCompanyID','320px','60%')",validate="{required:true,messages:{required:'请选择承保公司'}}" })
            @Html.HiddenFor(m => m.InsuranceCompanyID)
        </div>
    </div>
    <div class="control-group hidden" id="divServiceProviderID">
        <label class="control-label">所属服务商:</label>
        <div class="controls">
            @Html.DropDownListFor(m => m.ServiceProviderID, ConvertToSelector.Instance.ServiceProviderConvertToSelectList(), new { validate = "{required:true,messages:{required:'请选择服务商'}}" })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">用户名字:</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.UserDisPlayName, new { @class = "col-sm-8", validate = "{required:true,messages:{required:'请输入用户名'}}" })
        </div>
    </div>
    if (id == 0)
    {
        <div class="control-group" id="div_add_admin_password">
            <label class="control-label">密码:</label>
            <div class="controls">
                @Html.PasswordFor(m => m.Password, new { @class = "col-sm-8", validate = "{required:true,minlength:6,messages:{required:'请输入密码'}}" })
            </div>
        </div>
    }
    <div class="control-group">
        <label class="control-label">手机号码:</label>
        <div class="controls">
            @Html.TextBoxFor(m => m.UserPhone, new { @class = "col-sm-8",maxlength=11 })
        </div>
    </div>
    <div class="control-group">
        <label class="control-label">是否可登录</label>
        <div class="controls">
            <label> @Html.RadioButtonFor(m => m.IsAvailable, "true", new { @name = "IsAvailable" }) 可登陆</label>
            <label> @Html.RadioButtonFor(m => m.IsAvailable, "false", new { @name = "IsAvailable" })  不可登陆</label>
        </div>
    </div>
    <div class="align-center">
        <button class="btn btn-primary Edit-R" type="submit">
            <i class="icon-ok bigger-110"></i>
            保存
        </button>
        <button class="btn" type="reset" data-dismiss="modal" onclick="parent.layer.closeAll()">
            <i class="icon-undo bigger-110"></i>
            取消
        </button>
    </div>
}
<script type="text/javascript">
    $(function() {
        userTypeChange();
    })
    function userTypeChange() {
        var userType = $("#UserType").val();
        if (userType == "@((byte)UserType.InsuranceCompanyUser)") {
            $("#divInsuranceCompanyID").removeClass("hidden");
            $("#divServiceProviderID").addClass("hidden");
        } else if (userType == "@((byte)UserType.ServiceProviderUser)") {
            $("#divServiceProviderID").removeClass("hidden");
            $("#divInsuranceCompanyID").addClass("hidden");
        }
    }
</script>